/**
 * Created by lional on 16/10/2.
 */

jGame.Text = ccui.Text.extend(/** @lends jGame.Text# */{

    ctor: function (textContent, fontName, fontSize) {
        if (fontName && fontName instanceof cc.FontDefinition) {
            this._super(textContent, fontName.fontName, fontName.fontSize);
            this._updateWithTextDefinition(fontName);
        } else {
            this._super(textContent, fontName, fontSize);
        }
        //cc.log("jGame.Text#ctor()");
    },

    //set the text definition for this label
    _updateWithTextDefinition: function (textDefinition) {
        if (textDefinition.fontSize) {
            this.setFontSize(textDefinition.fontSize);
        }
        if (textDefinition.fontName) {
            this.setFontName(textDefinition.fontName);
        }
        if (textDefinition.boundingWidth) {
            this.boundingWidth = textDefinition.boundingWidth;
        }
        if (textDefinition.boundingHeight) {
            this.boundingHeight = textDefinition.boundingHeight;
        }

        if (textDefinition.textAlign) {
            this.textAlign = textDefinition.textAlign;
        }
        if (textDefinition.verticalAlign) {
            this.verticalAlign = textDefinition.verticalAlign;
        }

        if (textDefinition.lineHeight) {
            this._lineHeight = textDefinition.lineHeight
        }

        if (textDefinition.fontStyle) {
            this.font = textDefinition.fontStyle;
        }


        // shadow
        if (textDefinition.shadowEnabled) {
            var color = cc.color.BLACK;
            if(textDefinition.fontWeight) {
                color = cc.hexToColor(textDefinition.fontWeight);
            }
            if(textDefinition.shadowOpacity) {
                color.a = textDefinition.shadowOpacity;
            }
            this.enableShadow(color,
                cc.size(textDefinition.shadowOffsetX, textDefinition.shadowOffsetY),
                textDefinition.shadowBlur);
        }

        // stroke
        if (textDefinition.strokeEnabled) {
            this.enableOutline(textDefinition.strokeStyle, textDefinition.lineWidth);
        }

        // fill color
        if(textDefinition.fillStyle) {
            this.setTextColor(textDefinition.fillStyle);
        }
    },

});